package com.wxy.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wxy.domain.User;
import com.wxy.domain.myException;
import com.wxy.service.userService;

import jakarta.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/sc01")
public class myController {
	@Autowired
	private userService userService;
	private static final Logger LOGGER=LoggerFactory.getLogger(myController.class);
	@RequestMapping("/{id}")				//使用restTemplate手动发送http请求，使用restful风格的controller接收
	@ResponseBody
	public User findById(@PathVariable(value = "id") int id) {
		return userService.findById(id);
	}
	@RequestMapping("/getId")					//使用openfeign发送http get请求
	@ResponseBody
	public User findById2(@RequestParam("id")int id) {
		LOGGER.info("接收到orderservice的查询id为"+id);
		return userService.findById(id);
	}
	@RequestMapping("/getId2")
	@ResponseBody
	public User findById3(HttpServletRequest request) {
		String idString=request.getParameter("id");
		int id=Integer.parseInt(idString);
		return userService.findById(id);
	}
}
